package medium;
/*
98. 验证二叉搜索树
解题思路：中序遍历，左右子树还有树本身，都必须满足二叉搜索树的条件，根据中序遍历的特点，对二叉树进行遍历，当当前节点值小于前一个时，继续遍历，否则说明不满足二叉搜索树的要求
 */
public class LeeCode98 {

  public static void main(String[] args) {

  }

  long pre = Long.MIN_VALUE;

  public boolean isValidBST(TreeNode root) {
    if (root == null){
      return true;
    }

    if (!isValidBST(root.left)){
      return false;
    }

    if (pre >= root.val){
      return false;
    }

    pre = root.val;

    if (!isValidBST(root.right)){
      return false;
    }

    return true;
  }



  public class TreeNode {
      int val;
    TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
        this.left = left;
         this.right = right;
      }
  }
}
